<!DOCTYPE html>
<html>
<head>
    <title>用户密码管理</title>
    <#include "/header.html">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div style="margin: 10px 0">
            <form class="layui-form layui-form-pane" action="" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">昵称</label>
                        <div class="layui-input-inline" id="positionListBox">
                        	<input type="text" name="username" placeholder="搜索昵称" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-primary layui-border-blue" lay-submit lay-filter="form-search-btn"><i class="layui-icon layui-icon-search"></i>搜索</button>
                        <button class="layui-btn layui-btn-primary" lay-submit lay-filter="form-reset-btn"><i class="layui-icon layui-icon-refresh"></i>重置</button>
                    </div>
                </div>
            </form>
        </div>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>


<script type="text/html" id="currentTableStatusTpl">
    {{# if(d.status == 1){ }}
    <span class="layui-badge layui-bg-green">启用</span>
    {{# } else { }}
    <span class="layui-badge layui-bg-grey">禁用</span>
    {{# } }}
</script>
<script type="text/html" id="currentTableAuthStatusTpl">
    {{# if(d.authStatus == 1){ }}
    <span class="layui-badge layui-bg-grey">待审核</span>
    {{# } else if(d.authStatus == 0){ }}
    <span class="layui-badge layui-bg-red">未认证</span>
    {{# }else if(d.authStatus == 2){ }}
    <span class="layui-badge layui-bg-green">已认证</span>
    {{# }else if(d.authStatus == 3){ }}
    <span class="layui-badge layui-bg-red">被驳回</span>
    {{# } }}
</script>
<script type="text/html" id="currentTableBar">
    <#if shiro.hasPermission("app:pwd:up")>
    <a class="layui-btn layui-btn-primary layui-border-green layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>认证</a>
    </#if>
    <#if shiro.hasPermission("app:pwd:update")>
    <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="pwd"><i class="layui-icon layui-icon-edit"></i>修改密码</a>
    </#if>
</script>

<script type="text/javascript">
    var formDataId = 0;
    var positionList = [];
    layui.use(['form', 'table', 'laytpl'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laytpl = layui.laytpl;
        tableSearch({},'user/list');
        
        function tableSearch(data,url) {
        	var tablethis = table.render({
                elem: '#currentTableId',
			    where:data,
                url: serverUrl(url),
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter'],
                cols: [[
                    {type: "numbers", width: 50},
                    {field: 'username', title: '昵称', width: 150},
                    {field: 'createTime', title: '注册时间', width: 130},
                    {field: 'loginIp', title: '登录ip', width: 150},
                    {field: 'loginApp', title: '登录app', width: 150},
                    {field: 'loginDeviceOs', title: '登录设备', width: 150},
                    {field: 'loginTime', title: '最后登录时间', width: 150, templet: function (d) {return '<div>'+d.loginTime+'</div>' + '<div>'+d.loginIp+'</div>';}},
                    {field: 'status', title: '状态', width: 80, templet: '#currentTableStatusTpl'},
                    {field: 'authStatus', title: '认证状态', width: 100, templet: '#currentTableAuthStatusTpl'},
                    {title: '操作', width: 200, toolbar: '#currentTableBar', align: "center"}
                ]],
                limits: [15, 30, 50],
                limit: 15,
                page: true
            });
        	return tablethis;
        };
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                formDataId = data.id;
                openFormView('app/pwd/verify.html', '认证');
                return false;
            } else if (obj.event === 'pwd') {
                formDataId = data.id;
                openFormView('app/pwd/form.html', '修改密码');
                return false;
            }
        });

        // 监听搜索操作
        form.on('submit(form-search-btn)', function (data) {
            //执行搜索重载
            if (data.field.username) {
            	tableSearch({"username":data.field.username},'user/search/username');
            //table.filterData(data.field.username);
	        } else {
	        	tableSearch({},'user/list');
	            //table.clearFilter();
	        }
	        return false;
	    });
        form.on('submit(form-reset-btn)', function (data) {
        	tableSearch({},'user/list');
            $("#searchForm")[0].reset();
            //table.clearFilter();
            return false;
        });

    });
</script>

</body>
</html>